/*
 * Copyright 2002-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package carson.web.mvc;

import org.springframework.core.style.StylerUtils;
import org.springframework.web.util.UrlPathHelper;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 当一个Http请求没有找到指定的Action方法时抛出此异常
 *
 * @author Carson Chen
 */
@SuppressWarnings("serial")
public class NoSuchActionHandlingMethodException extends ServletException {

	private String methodName;

	/**
	 * 实例化NoSuchActionHandlingMethodException
	 * @param urlPath 请求的url
	 * @param method the HTTP request method of the request
	 * @param parameterMap the request's parameters as map
	 */
	public NoSuchActionHandlingMethodException(String urlPath, String method, Map<String, String[]> parameterMap) {
		super("servlet请求没有找到指定的方法: url '" + urlPath +
				"', method '" + method + "', parameters " + StylerUtils.style(parameterMap));
	}

	/**
	 * 实例化NoSuchActionHandlingMethodException
	 * @param methodName the name of the handler method that wasn't found
	 * @param controllerClass the class the handler method was expected to be in
	 */
	public NoSuchActionHandlingMethodException(String methodName, Class<?> controllerClass) {
		super("servlet请求没有找到指定的方法: '" + methodName +
				"' in class [" + controllerClass.getName() + "]");
		this.methodName = methodName;
	}


	/**
	 * Return the name of the offending method, if known.
	 */
	public String getMethodName() {
		return this.methodName;
	}

}
